import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebSitePage extends StatefulWidget {
  const WebSitePage({Key key}) : super(key: key);

  @override
  _WebSitePageState createState() => _WebSitePageState();
}

class _WebSitePageState extends State<WebSitePage> {
  WebViewController controller;

  @override
  void initState() {
    super.initState();
    controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setNavigationDelegate(NavigationDelegate(
        onProgress: (progress) {
          print('--------> $progress');
        },
        onPageFinished: (url) {
          print('-------------> $url');
        },
        onNavigationRequest: (request) {
          print('===> ${request.url}');
          return NavigationDecision.navigate;
        },
      ))
      ..loadRequest(Uri.parse('https://pub-web.flutter-io.cn'));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter Simple Example'),
      ),
      body: Container(
        child: WebViewWidget(controller: controller),
      ),
    );
  }
}
